import config from "../../../config.js";
const openIdUrl = config;
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    manager: {
      header: "",
      name: "张伟",
      score: "9.0",
      level: 4.5,
      years:7,
      customers:256,
      location:"西安",
      detail: "../managerDetail/managerDetail"
    },

    recLIst: []
  },

  contact: function() {
    wx.makePhoneCall({
      phoneNumber: "400-9988-960",
    })
  },

  onLoad: function() {
    app.editTabBar();
    
    this.loadData();

  },
  tapAction: function(e) {
    console.log(e.currentTarget.dataset.url);
    wx.reLaunch({
      url: e.currentTarget.dataset.url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log(wx.getStorageSync("user"));
    var user = wx.getStorageSync("user");
    var score = user.housekeeper.score;
    var star = [];
    for (var i = 0; i < score; i++) {
      star.push(i);
    }
    this.setData({
      "manager.name": user.name,
      "manager.header": user.img,
      "manager.score": user.housekeeper.score,
      "manager.level": user.housekeeper.score,
      "manager.years": user.housekeeper.score,
      "manager.customers": user.housekeeper.orders,
      "manager.location": user.housekeeper.location,
      "manager.star": star,
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  loginOut: function() {
    var that = this;
    wx.showToast({
      title: '注销中...',
      icon: "loading",
      mask: true
    })
    wx.request({
      url: openIdUrl.loginOut,
      header: {
        'Cookie': wx.getStorageSync("session")
      },
      success: function () {
        wx.clearStorage();
        wx.setStorageSync('user', null);
        wx.setStorageSync('isLogin', false);
        wx.setStorageSync('userType', null);
        wx.setStorageSync('openID', null);
        wx.setStorageSync('session', null);
        wx.reLaunch({
          url: '../../login/login',
        })

        wx.showToast({
          title: '退出成功！',
          icon: "loading",
          mask: true,
          duration: 1000
        })
      }
    })
  },
   loadData: function () {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: openIdUrl.ordersGJList,
      data: {
        start: 0,
        length: 5,
        type:0,
        search: ''
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': wx.getStorageSync("session")
      },
      success: function (res) {
        console.log(res);
        wx.hideLoading();
        if (res.data.status == 200) {
          that.setData({
            recLIst: res.data.data
          })

        } else {
          wx.hideLoading();
          wx.showToast({
            title: res.data.message + "",
            icon: 'none',
            mask: true,
            duration: 2000
          })
        }

      },
      error: function () {
        wx.showToast({
          title: "请求失败,请联系管理员",
          icon: 'none',
          mask: true,
          duration: 2000
        })
      }
    })

  },
  changeInfo:function(){
    wx.navigateTo({
      url: '../mine/mineinfo',
    })
  }
})